<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/8/9
 * Time: 3:34 PM
 */
namespace app\common\models;

class Area extends BaseModel
{

    public $timestamps = false;

    public $table = 'yq_area';

    protected $guarded = [''];

    protected $fillable = [''];


    public static function getProvince()
    {
        return self::where('level', '1')->get();
    }

    public static function getCityByParentId($parentId)
    {
        return self::where('pid', $parentId)
            ->where('level', '2')
            ->get();
    }

    public static function getAreaByParentId($parentId)
    {
        return self::where('pid', $parentId)
            ->where('level', '3')
            ->get();
    }

    public static function getAreaByIds($ids)
    {
        return self::whereIn('id', $ids)
            ->get();
    }

    public function hasOneParent()
    {
        return $this->hasOne(self::class, 'id', 'pid');
    }

}